package com.mall.product.controller;

import com.mall.common.domain.MallProduct;
import com.mall.common.domain.Numbers;
import com.mall.common.domain.request.MallProductRequest;
import com.mall.common.result.Result;
import com.mall.product.service.ProductInfoService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author wangy
 * @version 1.0
 * @description: TODO 商品信息控制层
 */
@RestController
public class ProductInfoController {
    @Resource
    private ProductInfoService productInfoService;

    /**
     * 选择产品列表
     *
     * @param mallProductRequest 参数
     * @return Result<List < MallProduct>>
     */
    @PostMapping("productList")
    public Result<List<MallProduct>> selectProductList(@RequestBody MallProductRequest mallProductRequest) {
        List<MallProduct> mallProducts = productInfoService.selectProductList(mallProductRequest);
        return Result.success(mallProducts);
    }

    /**
     * 添加商品信息
     * @param mallProduct  参数
     * @return Result
     */
    @PostMapping("addProduct")
    public Result addProduct(@RequestBody MallProduct mallProduct){
        if (mallProduct==null){
            throw new RuntimeException("参数不能为空");
        }
        productInfoService.addProduct(mallProduct);
        return Result.success();
    }




    @PostMapping("statisticsUser")
    public Result<List<Numbers>> statisticsUser() {
        List<Numbers> numbers = productInfoService.statisticsUser();
        return Result.success(numbers);
    }

}
